package com.deductive.service.special.impl;

import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.lang.tree.TreeNodeConfig;
import cn.hutool.core.lang.tree.TreeUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.deductive.domain.special.SpecialAirport;
import com.deductive.service.special.SpecialAirportService;
import com.deductive.mapper.special.SpecialAirportMapper;
import org.springframework.stereotype.Service;

import java.util.List;


/**
* @author 47338
* @description 针对表【special_airport(机场)】的数据库操作Service实现
* @createDate 2025-09-01 16:24:02
*/
@Service
public class SpecialAirportServiceImpl extends ServiceImpl<SpecialAirportMapper, SpecialAirport>
    implements SpecialAirportService {


    @Override
    public List<Tree<Object>> listTree() {
        TreeNodeConfig treeNodeConfig = new TreeNodeConfig();
        treeNodeConfig.setIdKey("id");
        treeNodeConfig.setNameKey("name");
        treeNodeConfig.setParentIdKey("parentId");
        List<SpecialAirport> list = this.list();
        List<Tree<Object>> treeList = TreeUtil.build(list, 0, treeNodeConfig, (specialHospital, tree) -> {
            tree.setId(specialHospital.getId()); // 设置节点ID
            tree.setName(specialHospital.getName()); // 设置节点名称（显示文本）
            tree.setParentId(specialHospital.getParentId());
            tree.putExtra("countryName", specialHospital.getCountryName());
            tree.putExtra("englishName", specialHospital.getEnglishName());
            tree.putExtra("type", specialHospital.getType());
            tree.putExtra("address", specialHospital.getAddress());
            tree.putExtra("overview", specialHospital.getOverview());
            tree.putExtra("runwayLength", specialHospital.getRunwayLength());
            tree.putExtra("runwayWidth", specialHospital.getRunwayWidth());
            tree.putExtra("icaoCode", specialHospital.getIcaoCode());
            tree.putExtra("iataCode", specialHospital.getIataCode());
            tree.putExtra("grade", specialHospital.getGrade());
            tree.putExtra("area", specialHospital.getArea());
            tree.putExtra("provideName", specialHospital.getProvideName());
            tree.putExtra("model", specialHospital.getModel());
            tree.putExtra("source", specialHospital.getSource());
            tree.putExtra("lon", specialHospital.getLon());
            tree.putExtra("lat", specialHospital.getLat());
        });
        return treeList;
    }
}